# coding: utf8

def index():
    example="""
# Title
## Section
### Subsection
This is a paragraph with **bold**, ''italic'', ``verbatim`` and [[a link http://web2py.com]]. Below is a formula:

$$\int_a^b sin(x)dx$$

Here is code with syntax highlighting (support cpp, java, python, html)

``
<html><body>Hello World</body></html>
``:code_html

Here is a table:

-----
A | B | C
1 | 2 | 3
4 | 5 | 6
-----

## References
- [[citation]] [reference] Neo, International Journal of Matrix Manipulation (2010)

    """
    form=SQLFORM.factory(Field('text_input','text',default=example),formstyle='table2cols')
    if form.accepts(request,keepvalues=True):
        LATEX = '<img src="http://chart.apis.google.com/chart?cht=tx&chl=%s" align="center"/>'
        extra = {
            'latex':lambda code: LATEX % code.replace('"','"'),
            'code_cpp':lambda text: CODE(text,language='cpp').xml(),
            'code_java':lambda text: CODE(text,language='java').xml(),
            'code_python':lambda text: CODE(text,language='python').xml(),
            'code_html':lambda text: CODE(text,language='html').xml()}
        output=MARKMIN(form.vars.text_input,extra)
    else:
        output=''
    return dict(form=form,output=output)

def help():
    example="""
# Title
## Section
### Subsection
This is a paragraph with **bold**, ''italic'', ``verbatim`` and [[a link http://web2py.com]]. Below is a formula:

$$\int_a^b sin(x)dx$$

Here is code with syntax highlighting (support cpp, java, python, html)

``
<html><body>Hello World</body></html>
``:code_html

Here is a table:

-----
A | B | C
1 | 2 | 3
4 | 5 | 6
-----

## References
- [[citation]] [reference] Neo, International Journal of Matrix Manipulation (2010)

    """
    form=SQLFORM.factory(Field('text_input','text',default=example),formstyle='table2cols')
    if form.accepts(request,keepvalues=True):
        LATEX = '<img src="http://chart.apis.google.com/chart?cht=tx&chl=%s" align="center"/>'
        extra = {
            'latex':lambda code: LATEX % code.replace('"','"'),
            'code_cpp':lambda text: CODE(text,language='cpp').xml(),
            'code_java':lambda text: CODE(text,language='java').xml(),
            'code_python':lambda text: CODE(text,language='python').xml(),
            'code_html':lambda text: CODE(text,language='html').xml()}
        output=MARKMIN(form.vars.text_input,extra)
    else:
        output=''
    return dict(form=form,output=output)


def error():
    return dict()
